"""检查数据库中的数据累积情况"""

import json
from app.models.brain_wave import BrainWave

def check_database_data():
    """检查数据库中的数据"""
    print("检查数据库中的脑波数据...")
    
    # 获取最近的5条记录
    records = BrainWave.select().order_by(BrainWave.id.desc()).limit(10)
    
    for record in records:
        print(f"\n=== 记录 ID: {record.id} ===")
        print(f"Room ID: {record.room_id}")
        print(f"总时长: {record.total_seconds}秒")
        print(f"开始时间: {record.start_time}")
        print(f"结束时间: {record.end_time}")
        
        # 检查各频段数据
        frequency_bands = ['delta_data', 'theta_data', 'eeg_wave_data']
        
        for band in frequency_bands:
            data_str = getattr(record, band, None)
            if data_str:
                try:
                    data = json.loads(data_str)
                    wave_frames = len(data.get('wave', {}).get('frames', []))
                    filtered_frames = len(data.get('filtered', {}).get('frames', []))
                    frame_rate = data.get('frame_rate', 'N/A')
                    
                    print(f"  {band}: wave={wave_frames}, filtered={filtered_frames}, rate={frame_rate}")
                except json.JSONDecodeError:
                    print(f"  {band}: JSON解析错误")
            else:
                print(f"  {band}: 无数据")

if __name__ == "__main__":
    check_database_data()